package com.example.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/v1/test")
public class RedisController {

    @Autowired
    // 系统默认的StringRedisTemplate;
    private StringRedisTemplate stringRedisTemplate;

    @Resource
    private RedisUtils redisUtils;

    //添加
    @PostMapping(value = "/add")
    public void saveReids(){
        redisUtils.set("test-key2","test-value");
//        stringRedisTemplate.opsForValue().set("test-key","test-value");
    }

    //获取
    @GetMapping(value = "/get")
    public String getRedis() {
        return redisUtils.get("test-key2").toString();
//        return stringRedisTemplate.opsForValue().get("test-key");
    }

}
